package com.symaster.backups.frame.element.table;

import lombok.Getter;

import javax.swing.*;

/**
 * @author yinmiao
 * @version 2024/2/5
 */
@Getter
public class Table extends JComponent {

    private int headHeight = 35;
    private boolean horizontalDivider = true;
    private boolean verticalDivider = true;
    private boolean headFloat = true;

    public void setHeadHeight(int headHeight) {
        this.headHeight = headHeight;
        repaint();
    }

    public void setHorizontalDivider(boolean horizontalDivider) {
        this.horizontalDivider = horizontalDivider;
        repaint();
    }

    public void setVerticalDivider(boolean verticalDivider) {
        this.verticalDivider = verticalDivider;
        repaint();
    }

    public void setHeadFloat(boolean headFloat) {
        this.headFloat = headFloat;
        repaint();
    }

    public Table() {
        setLayout(new TableLayout(this));
        super.setUI(TableUI.createUI(this));
    }

    public void addColumn(String columnName, int columnWidth) {
        if (getLayout() instanceof TableLayout tableLayout) {
            tableLayout.addColumn(columnName, columnWidth);
        }
    }

    public void addColumn(int columnIndex, String columnName, int columnWidth) {
        if (getLayout() instanceof TableLayout tableLayout) {
            tableLayout.addColumn(columnIndex, columnName, columnWidth);
        }
    }
}
